//
//  CacheDB.h
//  TravelGuideMdd
//
//  Created by BigPolarBear on 13-5-25.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "YWFoundation.h"


@interface CacheItem : NSObject

@property (nonatomic,readonly) NSString* key;
@property (nonatomic,readonly) NSString* value;
@property (nonatomic,readonly) NSDate* utime;
@property (nonatomic,readonly) NSDate* ctime;

@end



#define CacheDBKey(NAME) CREATE_KEY(NAME,CACHEDB)
#define CacheDBVarKey(VAR,NAME) CREATE_KEY_VALUE(VAR,NAME,CACHEDB)

/** @name 缓存库 */
@interface CacheDB : NSObject

/** 单例 */
+(CacheDB*)defaultCacheDB;

/** 设置KV缓存值 */
+(void)setValue:(NSString*)value forKey:(NSString*)key;
/** 获取KV缓存值 */
+(NSString*)valueForKey:(NSString*)key;

/** 设置KV缓存值：数组 */
+(void)setValueArray:(NSArray*)array forKey:(NSString*)key;
/** 获取KV缓存值：数组 */
+(NSArray*)valueArrayForKey:(NSString*)key;

/** 设置KV缓存：字典 */
+(void)setValueDict:(NSDictionary*)dict forKey:(NSString*)key;
/** 获取KV缓存：字典 */
+(NSDictionary*)valueDictForKey:(NSString*)key;

/** 返回缓存数据：含创建时间、更新时间等 */
+(CacheItem*)cacheItemForKey:(NSString*)key;

-(BOOL)deleteAllCache;


#pragma mark
#pragma mark KVCache缓存表相关

/** 持久化缓存 */
-(void)setKVCacheValue:(NSString*)value forKey:(NSString*)key;

/** 返回缓存的value对象*/
-(NSString*)getKVCacheValueForKey:(NSString*)key;

/** 返回缓存数据：含创建时间、更新时间等 */
-(CacheItem*)cacheItemForKey:(NSString*)key;

/** 返回缓存数据数组：指定key前缀 */
-(NSArray*)listCacheItemWithKeyPrefix:(NSString*)keyPrefix;
@end
